package com.zzyl.controller.customer;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.bookingDto;
import com.zzyl.service.bookingService;
import com.zzyl.vo.BookingVo;
import com.zzyl.vo.bookingCountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/customer/reservation")
@Api(tags = "预约模块")
public class ConstomerbookingController extends BaseController {

    @Autowired
    private bookingService bookingService;

    /**
     * 查询取消预约数量
     * @return
     */
    @ApiOperation("查询取消预约数量")
    @GetMapping("/cancelled-count")
    private ResponseResult getBookingUnit(){
        Integer count =  bookingService.getCountData();//调用Service层方法 无需参数
        return ResponseResult.success(count);//返回值为当前用户的当天取消数量
    }

    /**
     * 新增预约
     * @param bookingdto
     * @return
     */
    @ApiOperation("新增预约")
    @PostMapping
    private ResponseResult addBooking(@RequestBody @ApiParam("新增预约信息") bookingDto bookingdto){
        bookingService.addbooking(bookingdto);//调用Service层新增方法
        return success();//返回正常响应信息
    }

    /**
     * 分页查询预约
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询预约")//接收参数为 页码 每页数量 和 状态
    private ResponseResult<PageResponse<BookingVo>> GetBookingPage(
        @RequestParam(value = "pageNum") @ApiParam("页码") Integer pageNum,
        @RequestParam(value = "pageSize") @ApiParam("每页数量") Integer pageSize,
        @RequestParam(value = "status",required = false) @ApiParam("状态") Integer status
    ){//调用Service层的分页查询方法 返回值为分页实体类包含预约视图对象 将参数传递给Service层
        PageResponse<BookingVo> bookingVoPageResponse = bookingService.getPage(pageNum,pageSize,status);
        return ResponseResult.success(bookingVoPageResponse);//返回查询到的结果
    }

    /**
     * 取消预约
     * @param id
     * @return
     */
    @ApiOperation("取消预约")
    @PutMapping("/{id}/cancel")//接收参数为预约信息的主键id
    private ResponseResult deleteBooking(@ApiParam("取消预约id") @PathVariable Long id){
        bookingService.updateBooking(id);//调用Service层的修改方法
        return success();//返回正常响应信息
    }

    /**
     * 查询每个时间段剩余预约次数
     * @return
     */
    @ApiOperation("查询每个时间段剩余预约次数")
    @GetMapping("/countByTime")//接收参数为一个时间戳对象
    private ResponseResult<List<bookingCountVo>> getBookingCountData(
            @ApiParam("时间戳") @RequestParam(value = "time") Long time){
        //1.将这个时间戳转换成LocalDateTime 调用Service层方法传递给Service //返回值为一个集合存储的是一个对象
        //对象中包含time count
        List<bookingCountVo> bookingCountVos =  bookingService.getCountVo(LocalDateTimeUtil.of(time));
        return ResponseResult.success(bookingCountVos);//将集合返回出去
    }





}

